package com.atguigu.controller;

import com.atguigu.pojo.Employee;
import com.atguigu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-01-18
 * @Description:
 * @Version: 1.0
 */
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    @PostMapping("/emp")
    public String add(@RequestBody Employee employee){
        empService.add(employee);
        return "{'status':'ok'}";
    }

    @PutMapping("/emp")
    public String update(@RequestBody Employee employee){
        empService.update(employee);
        return "{'status':'ok'}";
    }

    @DeleteMapping("/emp/{eid}")
    public String delete(@PathVariable Integer eid){
        empService.delete(eid);
        return "{'status':'ok'}";
    }

    @GetMapping("/emp/{eid}")
    public Employee selectById(@PathVariable Integer eid){
        Employee employee = empService.SelectEmpById(eid);
        employee.toString();
        return employee;
    }

    @GetMapping("/emp")
    public List<Employee> selectAll(){
        List<Employee> employees = empService.SelectAllEmp();
        employees.forEach(employee -> employee.toString());
        return employees;
    }

}
